package com.cloud.alarm.dinger.bytetalk.entity;

import com.cloud.alarm.dinger.bytetalk.entity.enums.ByteTalkMsgType;
import com.cloud.alarm.dinger.support.sign.SignBase;
import com.cloud.alarm.dinger.support.sign.SignResult;
import lombok.Getter;

import java.io.Serial;

/**
 * @description:
 * @author: zhou shuai
 * @date: 2024/7/12 16:11
 * @version: v1
 */
@Getter
public class ByteInteractive extends ByteTalkMessage {

    @Serial
    private static final long serialVersionUID = -4341286158193776281L;

    /**
     * 消息类型
     */
    private final String msg_type;
    /**
     * 消息卡片
     */
    private final ByteCard card;
    /**
     * 签名-时间戳
     */
    private String timestamp;
    /**
     * 签名-秘钥
     */
    private String sign;

    public ByteInteractive(String title, String content) {
        this.msg_type = ByteTalkMsgType.INTERACTIVE.getType();
        this.card = new ByteCard(title, content);
    }

    @Override
    public void signAttributes(SignBase sign) {
        if (!(sign instanceof SignResult signResult)) {
            return;
        }
        this.timestamp = String.valueOf(signResult.getTimestamp());
        this.sign = signResult.getSign();
    }

}
